package com.qf.lanzhou.blog.api.controller.notification;

import com.qf.lanzhou.blog.api.controller.BaseServletPost;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.NotificationService;
import com.qf.lanzhou.blog.api.service.impl.NotificationServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 是柠檬甜
 * @ClassName NotificationAddServlet
 * @description 添加通知信息
 * @date 2020/12/16 20:48
 * @modifier 是柠檬甜
 * @date 2020-12-16 20:48
 * @Version V1.0
 */
@WebServlet("/addNotification.do")
public class NotificationAddServlet extends BaseServletPost {
    private NotificationService notificationService=new NotificationServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取参数
        String content = req.getParameter("content");
        User user = (User) req.getSession().getAttribute("user");
        try{
            Boolean result = notificationService.addNotification(user.getUserName(), content);
            successResultWrite("添加成功",resp);
        }catch (RuntimeException e){
            String message = e.getMessage();
            failedResultWrite(message,resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
